package io.github.lee.repository.jel.data

import android.content.Context
import androidx.annotation.Keep
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import io.github.lee.repository.jel.dao.SessionDatabaseModel

val Context.session: Session?
    get() {
        val dao = SessionDatabaseModel.provideSessionDatabase(this)
            .sessionDao()
        return dao.current()
    }


@Keep
@Entity
data class Session(

    @ColumnInfo var name: String,
    @ColumnInfo var host: String,
    @ColumnInfo var username: String,
    @ColumnInfo var password: String,
    @ColumnInfo var userId: String?,
    @ColumnInfo var token: String?,

    @PrimaryKey(autoGenerate = true) var id: Long? = null,

    @ColumnInfo(name = "create_time") var createTime: Long = System.currentTimeMillis(),
    @ColumnInfo(name = "update_time") var updateTime: Long = System.currentTimeMillis(),
    @ColumnInfo(name = "select_time") var selectTime: Long = System.currentTimeMillis(),
)
